<template>
	<view>
		<scroll-view class="Tab-Control" scroll-x="true" id="top">
			<view class="nav">
				<view v-for="item in Controlnav " :key="item.id" :class="{
					'list': true,
					'oklist': item.id === Controllistnum
				}" @click="updateControllistclass(item.id, item.router)">
					{{ item.name }}
				</view>
			</view>
		</scroll-view>
		<view class="newslist">
			<view v-for="(item,index) in newslist" :key="index">
				<view class="item" @click="newsnavTo(Controllistnum,item.id)">
					<view class="title">
						{{item.title}}
					</view>
					<view class="date">
						{{item.information}}
					</view>
				</view>
			</view>
		</view>
		<view class="arrow">
			<image src="../../static/arrow-up.png" mode="aspectFit" class="img" @click="up()"></image>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Controlnav: [{
						id: 1,
						name: '党委学生工作部'
					},
					{
						id: 2,
						name: '教育基金会'
					},
					{
						id: 3,
						name: '教育基金会'
					},
					{
						id: 4,
						name: '教育基金会'
					},
					{
						id: 5,
						name: '教育基金会'
					},
					{
						id: 6,
						name: '党委学生工作部'
					}
				],
				Controllistnum: 1,
				newslist: ''
			};
		},
		methods: {
			updateControllistclass(id) {
				this.Controllistnum = id
				uni.request({
					url: 'http://120.78.179.141:9876/page?pageID=' + JSON.stringify(this.Controllistnum),
					method: "GET",
					success: (res) => {
						console.log(res.data);
						this.newslist = res.data.data;
					},
					fail: (res) => {
						console.log(res.errMsg);
					}
				});
			},
			newsnavTo(pageid, newsid) {
				uni.navigateTo({
					url: "/pages/news/news?pageID=" + pageid + "&newsID=" + newsid
				});
			},
			up() {
				uni.createSelectorQuery().select('#top').boundingClientRect(data => { //目标位置的节点：类或者id
					uni.createSelectorQuery().select("#top").boundingClientRect(res => { //最外层盒子的节点：类或者id
						uni.pageScrollTo({
							duration: 100, //过渡时间
							scrollTop: data.top - res.top, //到达距离顶部的top值
						})
					}).exec()
				}).exec();
			}
		},
		onReady() {
			uni.request({
				url: 'http://120.78.179.141:9876/page?pageID=' + JSON.stringify(this.Controllistnum),
				method: "GET",
				success: (res) => {
					console.log(res.data);
					this.newslist = res.data.data;
				},
				fail: (res) => {
					console.log(res.errMsg);
				}
			});
		},
		onPullDownRefresh() {
			uni.request({
				url: 'http://120.78.179.141:9876/page?pageID=' + JSON.stringify(this.Controllistnum),
				method: "GET",
				success: (res) => {
					console.log(res.data);
					this.newslist = res.data.data;
				},
				fail: (res) => {
					console.log(res.errMsg);
				}
			});
		}
	}
</script>

<style lang="scss">
	.Tab-Control {
		white-space: nowrap;
		background-color: #fff;

		.nav {
			font-size: 32rpx;
			color: #8d8d8e;
			font-weight: 600;

			display: flex;

			.list {
				box-sizing: border-box;
				padding: 15rpx;
				border-bottom: 2px solid #e5e5e5;
			}
		}

	}

	.oklist {
		color: #ba2a17 !important;
		border-bottom: 8rpx #ba2a17 solid !important;
		border-radius: 0 0 2rpx 2rpx;
	}

	.item {
		display: flex;
		flex-direction: column;
		padding: 15rpx 50rpx;
		border-bottom: 1px solid #e5e5e5;

		.title {
			font-weight: bold;
		}

		.date {
			margin-top: 10rpx;
			color: #8d8d8e;
			display: flex;
			justify-content: flex-end;
			font-size: 28rpx;
		}
	}

	.arrow {
		position: fixed;
		bottom: 100rpx;
		right: 50rpx;
		width: 100rpx;
		height: 100rpx;

		.img {
			width: 100%;
			height: 100%;
		}
	}
</style>
